from sqlalchemy.orm import Session

from . import models, schemas


def get_users(db: Session, skip: int = 0, limit: int = 100):
    return db.query(models.User).offset(skip).limit(limit).all()


def get_user_by_email(db: Session, user_email: str):
    result = db.query(models.User).filter(models.User.email == user_email).first()
    return result


def create_user(hashed_password: str, db: Session, user: schemas.UserCreate):
    db_user = models.User(email=user.email, hashed_password=hashed_password,
                          salary=user.salary, date=user.date)
    db.add(db_user)
    db.commit()
    db.refresh(db_user)
    return db_user

